<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var isHappy = function(n) {
    // 头节点一定存在
    let fast = getNext(n)
    let cur = n
    while(fast !==1 && cur !== fast) {
        cur = getNext(cur,'cur')
        fast = getNext(getNext(fast))
        console.log('内部的',fast);
    }
    console.log(fast);
    return fast === 1
}
function getNext(n, type='fast') {
    let sum = 0
    while(n) {
        sum += (n%10) * (n%10)
        n = Math.floor(n/10)
    }
    console.log('每一次的和' + type, sum);
    return sum
}
console.log(isHappy(2));
  </script>
</body>
</html>